namespace MsForgeReboot.Services.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitialDatabaseCreation : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.BlogPosts",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Body = c.String(nullable: false),
                        Published = c.DateTime(nullable: false),
                        Title = c.String(nullable: false, maxLength: 200),
                        UrlPointer = c.String(nullable: false, maxLength: 200),
                        Author_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Users", t => t.Author_Id)
                .Index(t => t.Author_Id);
            
            CreateTable(
                "dbo.Comments",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Body = c.String(nullable: false),
                        CommentBy = c.String(nullable: false, maxLength: 150),
                        Email = c.String(maxLength: 100),
                        CommentedOn = c.DateTime(nullable: false),
                        BlogPost_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.BlogPosts", t => t.BlogPost_Id)
                .Index(t => t.BlogPost_Id);
            
            CreateTable(
                "dbo.Tags",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Users",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Username = c.String(nullable: false, maxLength: 100),
                        PublicName = c.String(nullable: false, maxLength: 100),
                        ReceiveNotifications = c.Boolean(nullable: false),
                        IsValidated = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Feeds",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        URL = c.String(nullable: false, maxLength: 500),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Pages",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Body = c.String(nullable: false),
                        Published = c.DateTime(nullable: false),
                        Title = c.String(nullable: false, maxLength: 200),
                        UrlPointer = c.String(nullable: false, maxLength: 200),
                        Author_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Users", t => t.Author_Id)
                .Index(t => t.Author_Id);
            
            CreateTable(
                "dbo.Sections",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Order = c.Int(nullable: false),
                        Title = c.String(nullable: false, maxLength: 200),
                        UrlPointer = c.String(nullable: false, maxLength: 255),
                        Page_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Pages", t => t.Page_Id)
                .Index(t => t.Page_Id);
            
            CreateTable(
                "dbo.Speakers",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        FirstName = c.String(nullable: false, maxLength: 50),
                        LastName = c.String(nullable: false, maxLength: 50),
                        Twitter = c.String(maxLength: 50),
                        LinkedIn = c.String(maxLength: 255),
                        Email = c.String(maxLength: 128),
                        Blog = c.String(maxLength: 255),
                        PicturePath = c.String(maxLength: 255),
                        City = c.String(nullable: false, maxLength: 50),
                        Biography = c.String(nullable: false),
                        UserProfile_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Users", t => t.UserProfile_Id)
                .Index(t => t.UserProfile_Id);
            
            CreateTable(
                "dbo.Events",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Topic = c.String(nullable: false, maxLength: 250),
                        UserGroup = c.String(nullable: false, maxLength: 100),
                        Begin = c.DateTime(),
                        End = c.DateTime(),
                        Venue = c.String(nullable: false, maxLength: 100),
                        Address_Street = c.String(maxLength: 50),
                        Address_StreetNumber = c.String(maxLength: 10),
                        Address_City = c.String(maxLength: 50),
                        Address_Country = c.String(maxLength: 50),
                        IsStreamingEvent = c.Boolean(nullable: false),
                        StreamingInstructions = c.String(nullable: false),
                        PicturePath = c.String(),
                        Body = c.String(nullable: false),
                        Published = c.DateTime(nullable: false),
                        Title = c.String(nullable: false, maxLength: 200),
                        UrlPointer = c.String(nullable: false, maxLength: 200),
                        Author_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Users", t => t.Author_Id)
                .Index(t => t.Author_Id);
            
            CreateTable(
                "dbo.TagBlogPosts",
                c => new
                    {
                        Tag_Id = c.Int(nullable: false),
                        BlogPost_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Tag_Id, t.BlogPost_Id })
                .ForeignKey("dbo.Tags", t => t.Tag_Id, cascadeDelete: true)
                .ForeignKey("dbo.BlogPosts", t => t.BlogPost_Id, cascadeDelete: true)
                .Index(t => t.Tag_Id)
                .Index(t => t.BlogPost_Id);
            
            CreateTable(
                "dbo.EventSpeakers",
                c => new
                    {
                        Event_Id = c.Int(nullable: false),
                        Speaker_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Event_Id, t.Speaker_Id })
                .ForeignKey("dbo.Events", t => t.Event_Id, cascadeDelete: true)
                .ForeignKey("dbo.Speakers", t => t.Speaker_Id, cascadeDelete: true)
                .Index(t => t.Event_Id)
                .Index(t => t.Speaker_Id);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.EventSpeakers", new[] { "Speaker_Id" });
            DropIndex("dbo.EventSpeakers", new[] { "Event_Id" });
            DropIndex("dbo.TagBlogPosts", new[] { "BlogPost_Id" });
            DropIndex("dbo.TagBlogPosts", new[] { "Tag_Id" });
            DropIndex("dbo.Events", new[] { "Author_Id" });
            DropIndex("dbo.Speakers", new[] { "UserProfile_Id" });
            DropIndex("dbo.Sections", new[] { "Page_Id" });
            DropIndex("dbo.Pages", new[] { "Author_Id" });
            DropIndex("dbo.Comments", new[] { "BlogPost_Id" });
            DropIndex("dbo.BlogPosts", new[] { "Author_Id" });
            DropForeignKey("dbo.EventSpeakers", "Speaker_Id", "dbo.Speakers");
            DropForeignKey("dbo.EventSpeakers", "Event_Id", "dbo.Events");
            DropForeignKey("dbo.TagBlogPosts", "BlogPost_Id", "dbo.BlogPosts");
            DropForeignKey("dbo.TagBlogPosts", "Tag_Id", "dbo.Tags");
            DropForeignKey("dbo.Events", "Author_Id", "dbo.Users");
            DropForeignKey("dbo.Speakers", "UserProfile_Id", "dbo.Users");
            DropForeignKey("dbo.Sections", "Page_Id", "dbo.Pages");
            DropForeignKey("dbo.Pages", "Author_Id", "dbo.Users");
            DropForeignKey("dbo.Comments", "BlogPost_Id", "dbo.BlogPosts");
            DropForeignKey("dbo.BlogPosts", "Author_Id", "dbo.Users");
            DropTable("dbo.EventSpeakers");
            DropTable("dbo.TagBlogPosts");
            DropTable("dbo.Events");
            DropTable("dbo.Speakers");
            DropTable("dbo.Sections");
            DropTable("dbo.Pages");
            DropTable("dbo.Feeds");
            DropTable("dbo.Users");
            DropTable("dbo.Tags");
            DropTable("dbo.Comments");
            DropTable("dbo.BlogPosts");
        }
    }
}
